<template>
	<view class="index-agent o-h" v-if="!loadding" :data-theme="theme()" :class="theme() || ''">
		<!--{{$t('agent.header_image')}}-->
		<view v-if="is_agent" class="banner d-c-c d-c">
			<image :src="top_background" mode="aspectFill"></image>
		</view>
		<view v-if="!is_agent" class="banner d-c-c d-c">
			<image :src="apply" mode="aspectFill"></image>
		</view>
		<!--{{$t('agent.is_distributor')}}-->
		<template v-if="is_agent && isData">
			<view class="info-top d-s-c">
				<view class="info-ava">
					<image class="info-avatar" :src="user.avatarUrl" mode="aspectFill"></image>
					<view class="info-grade" v-if="agent.gradeId > 0">{{
						agent.realName
					}}</view>
				</view>
				<view class="white d-c d-c-s flex-1 pr">
					<view class="mb20 f30 fb">{{ user.nickName }}</view>
					<view class="f22">{{ $lang(info_words.index, 'referee') || "" }}:{{
						agent.refereeNickname ? agent.refereeNickname : $t('agent.platform')
					}}</view>
				</view>
			</view>
			<!--{{$t('agent.amount_information')}}-->
			<view class="agent-wrap pr m-0-20">
				<view class="d-s-c p-30-0 top_dash">
					<view class="flex-1 d-c-c d-c">
						<view class="redF6">
							<text class="f36 fb">{{ agent.money }}</text>
						</view>
						<view class="pt20 f24 gray6">{{ $lang(info_words.index, 'money') }}</view>
					</view>
					<view class="flex-1 d-c-c d-c">
						<view class="">
							<text class="f36 fb">{{ agent.freezeMoney }}</text>
						</view>
						<view class="pt20 f24 gray6">{{
							$lang(info_words.index, 'freezeMoney')
						}}</view>
					</view>
					<view class="flex-1 d-c-c d-c">
						<view class="">
							<text class="f36 fb">{{ agent.totalMoney }}</text>
						</view>
						<view class="pt20 f24 gray6">{{
							$lang(info_words.index, 'totalMoney')
						}}</view>
					</view>
				</view>
				<view class="d-c-c pt30">
					<button type="primary" class="btn-gcred flex-1" @click="gotoCash">
						{{ $lang(info_words.index, 'cash') }}
					</button>
				</view>
			</view>
			<!--{{$t('agent.icon_entry')}}-->
			<view class="agent-wrap m-0-20 p30 d-s-c f-w mt20 bg-white">
				<view class="d-c-c d-c flex-1" @click="gotoPage('/pages/agent/cash/list/list')">
					<view>
						<image class="agent_index_img" src="../../../static/icon/icon-zijinmingxi.png" mode=""></image>
					</view>
					<text class="pt10 f26 mt20">{{ $lang(info_words.cashList, 'title') }}</text>
				</view>
				<view class="d-c-c d-c flex-1" @click="gotoPage('/pages/agent/order/order')">
					<view>
						<image class="agent_index_img" src="../../../static/icon/icon-fenxiaodingdan.png" mode="">
						</image>
					</view>
					<text class="pt10 f26 mt20">{{ $lang(info_words.order, 'title') }}</text>
				</view>
				<view class="d-c-c d-c flex-1" @click="gotoPage('/pages/agent/team/team')">
					<view>
						<image class="agent_index_img" src="../../../static/icon/icon-tuandui.png" mode=""></image>
					</view>
					<text class="pt10 f26 mt20">{{ $lang(info_words.team, 'title') }}</text>
				</view>
				<view class="d-c-c d-c flex-1" @click="gotoPage('/pages/agent/qrcode/qrcode')">
					<view>
						<image class="agent_index_img" src="../../../static/icon/icon-erweima.png" mode=""></image>
					</view>
					<text class="pt10 f26 mt20">{{ $lang(info_words.qrcode, 'title') }}</text>
				</view>
			</view>
		</template>
		<!--{{$t('agent.not_distributor')}}-->
		<template v-if="!is_agent && isData">
			<view class="no-agent">
				<image class="no-agent-image" src="/static/agent_no.png" mode=""></image>
				<view class="mt50 p-0-20 gray9 f30 tc">{{
					$lang(info_words.index, 'notAgent')
				}}</view>
				<view class="p30 mt30">
					<button type="primary" class="btn-gcred" @click="applyagent">
						{{ $lang(info_words.index, 'applyNow') }}
					</button>
				</view>
			</view>
		</template>
	</view>
</template>

<script>
export default {
	data() {
		return {
			/*是否加载完成*/
			loadding: true,
			indicatorDots: true,
			autoplay: true,
			interval: 2000,
			duration: 500,
			/*0：不是分销商，1：分销商申请中，2：已经是分销商*/
			is_agent: false,
			isData: false,
			agent: {},
			/*顶部背景*/
			top_background: "",
			/*基本信息*/
			info_words: {},
			words: {},
			user: {},
			titel: "",
			apply: '',
		};
	},
	onLoad(e) {
		if (e.is_agent) {
			this.is_agent = e.is_agent;
		}
	},
	onShow() {
		uni.showLoading({
			title: this.$t('agent.loading'),
		});
		/*获取个人中心数据*/
		this.getData();
		if (this.is_agent === 1) {
			uni.redirectTo({
				url: "pages/agent/apply/apply",
			});
		}
		uni.setNavigationBarTitle({
			title: this.$t('common.distribution_center')
		})
	},
	methods: {
		/*获取数据*/
		getData() {
			let self = this;
			self._get("user/agent/center", {}, function (res) {
				self.info_words = res.data.words;
				// uni.setNavigationBarTitle({
				// 	title: self.info_words.index.title != '' ? self.info_words.index.title : self.info_words.index.title
				// 		.default
				// });
				self.titel = res.data.words.index.title;
				self.is_agent = res.data.isAgent;
				if (res.data.isApplying === true && self.is_agent === false) {
					uni.redirectTo({
						url: "/pages/agent/apply/apply",
					});
				}
				self.top_background = res.data.background;
				self.apply = res.data.apply;
				self.agent = res.data.agent;
				self.user = res.data.user;
				self.isData = true;
				self.loadding = false;
				uni.hideLoading();
			});
		},

		/*申请分销商*/
		applyagent() {
			this.gotoPage("/pages/agent/apply/apply");
		},

		/*去商城逛逛*/
		gotoShop() {
			this.gotoPage("/pages/index/index");
		},

		/*去提现*/
		gotoCash() {
			this.gotoPage("/pages/agent/cash/apply/apply");
		},
		goback() {
			uni.navigateBack();
		},
	},
};
</script>

<style lang="scss">
page {
	background-color: #f9f9f9;
}

.index-agent .banner {
	position: absolute;
	width: 750rpx;
	height: 348rpx;
	z-index: 0;
	/* padding-bottom: 60rpx; */
	background-repeat: no-repeat;
	background-size: 100%;
}

.index-agent .banner image {
	width: 100%;
}

.no-agent-image {
	width: 532rpx;
	height: 340rpx;
	padding-top: 20rpx;
	margin: 0 auto;
	display: block;
}

.agent-wrap {
	background: #ffffff;
	background-size: 100% 100%;
	padding: 31rpx 25rpx 36rpx 25rpx;
	box-shadow: 0px 8rpx 3rpx 0px rgba(6, 0, 1, 0.03);
	border-radius: 20rpx;
}

.index-agent .agent-wrap .iconfont {
	font-size: 60rpx;
}

.index-agent .btn-gcred {
	height: 88rpx;
	line-height: 88rpx;
	border-radius: 44rpx;
	background: #ff5649;
	border-color: #ff5649;
}

.reg180 {
	padding-right: 20rpx;
	text-align: right;
	transform: rotateY(180deg);
	position: absolute;
	bottom: 0;
}

.icon-jiantou {
	color: #ffffff;
	font-size: 30rpx;
}

.head_top {
	position: absolute;
	width: 100%;
	height: 30px;
	line-height: 30px;
	color: #ffffff;
	font-size: 32rpx;
	z-index: 2;
}

.top_dash {
	padding-bottom: 9px;
}

.agent_index_img {
	width: 78rpx;
	height: 78rpx;
}

.info-top {
	padding: 74rpx 0 63rpx 44rpx;
}

.info-ava {
	width: 108rpx;
	height: 108rpx;
	border-radius: 50%;
	position: relative;
	margin-right: 30rpx;
}

.info-avatar {
	width: 108rpx;
	height: 108rpx;
	border-radius: 50%;
}

.info-grade {
	min-width: 114rpx;
	height: 30rpx;
	line-height: 30rpx;
	padding: 0 22rpx;
	box-sizing: border-box;
	font-size: 18rpx;
	color: #ffffff;
	background: #ffc519;
	box-shadow: 0px 3rpx 7rpx 0px rgba(0, 0, 0, 0.15);
	border-radius: 15rpx;
	text-align: center;
	white-space: nowrap;
	position: absolute;
	left: 0;
	right: 0;
	bottom: -16rpx;
	z-index: 2;
}
</style>